package testJdk.base.juc_test.multi_threading;

/**
 * @author Created by cyd on 2021-03-26 16:31:02
 * @Description : 描述
 */
public class DoubleCheckLockSingleton {
    // private static DoubleCheckLockSingleton instance = null;
    private static volatile DoubleCheckLockSingleton instance = null;

    private DoubleCheckLockSingleton() {
    }

    public static DoubleCheckLockSingleton getInstance() {
        if (instance == null) {
            // 防止并发线程穿透
            synchronized (DoubleCheckLockSingleton.class) {
                if (instance == null) {
                    instance = new DoubleCheckLockSingleton();
                }
            }
        }
        return instance;
    }
}
